<?php
/**
 *  This file is part of Urd.
 *
 *  Urd is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *  Urd is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program. See the file "COPYING". If it does not
 *  exist, see <http://www.gnu.org/licenses/>.
 *
 * $LastChangedDate: 2008-07-19 08:33:18 +0200 (Sat, 19 Jul 2008) $
 * $Rev: 1306 $
 * $Author: styck $
 * $Id: admin_config.php 1306 2008-07-19 06:33:18Z styck $
 */

define('ORIGINAL_PAGE', $_SERVER['PHP_SELF']);

$pathadc = realpath(dirname(__FILE__));

require_once "$pathadc/../functions/html_includes.php";
require_once "$pathadc/../functions/pref_functions.php";
require_once "$pathadc/../functions/periods.php";

if (!$isadmin)
    fatal_error($LN['error_noadmin']);

update_settings($db, SUPER_USERID);

$imported = $saved = 0;
$on_off = array ('on'=>$LN['on'], 'off'=>$LN['off']);
$cleandir_dirs = array ('all'=>$LN['all'], 'preview'=>$LN['preview'], 'tmp'=>$LN['temporary']);

try {
    $groups_orig = read_system_groups();
} catch (exception $e) {
    $__message[] = $e->getMessage();
    $groups_orig = array();
}

$all_users =  get_all_users($db);

sort($groups_orig);
$groups[''] = '';
foreach ($groups_orig as $g) {
    $groups["$g"] = $g;
}

$users[''] = '';
foreach ($all_users as $u) {
    $users["$u"] = $u;
}

$pref_level = get_request('pref_level', '');
$levels = get_user_levels();
if (! in_array($pref_level , array_keys($levels)))
    $pref_level = '';

if ($pref_level == '')
    $pref_level = get_pref($db, 'pref_level', $userID);


$index_page_array = get_index_page_array($isadmin);

$permissions = array (
    '' => $LN['config_perms']['none'],
    '0400'=>$LN['config_perms']['0400'],
    '0600'=>$LN['config_perms']['0600'],
    '0640'=>$LN['config_perms']['0640'],
    '0644'=>$LN['config_perms']['0644'],
    '0660'=>$LN['config_perms']['0660'],
    '0664'=>$LN['config_perms']['0664'],
    '0666'=>$LN['config_perms']['0666']
);

$templates =  get_templates();
$languages = get_languages();

$log_levels = array();
$rprefs = load_config($db);

foreach ($log_str as $level => $log)
    $log_levels[$level] = ucwords($log);

$searchbuttons = get_buttons($db);

$shaping_msg = $auto_expire_msg = $urdd_restart_msg = $nntp_useauth_msg = $auto_reg_msg = $register_msg = $hiddenfiles_msg = '';
$sendmail_msg = $webdownload_msg = $auto_download_msg = $check_nntp_connections_msg = $user_scripts_msg = $global_scripts_msg = '';
$parse_nfo_msg = $keep_int_msg = $compress_nzb_msg = ''; 
// URDD online?
$uc = new urdd_client($rprefs['urdd_host'], $rprefs['urdd_port'], $userID);
$URDDONLINE = $uc->is_connected();

if (isset($_POST['save_settings'])){
	header("Content-Type: text/html/force-download");
	header("Content-Disposition: attachment; filename=urd_config.xml");
    $xml = new urd_xml_writer('php://output');
    $xml->write_config($db);
    $xml->output_xml_data();
	die;
}

if(isset($_POST['load_settings'])) {
    verify_challenge($_POST['challenge']);
    $xml = new urd_xml_reader($_FILES['filename']['tmp_name']);
    $settings = $xml->read_config($db);
	if ($settings != array()) {
		clean_config($db);
		reset_config($db);
		set_configs($db, $settings);
		$imported = 1;
	} else {
		$__message[] = $LN['settings_notfound'];
	}
}

/* Save changes: */
if (isset($_POST['submit_button'])) {
    verify_challenge($_POST['challenge']);
    $db->escape($_POST); 

    if ($URDDONLINE) {
        try {
            list($pkeys, $ptexts) = $periods->get_periods();
            $uc = new urdd_client($rprefs['urdd_host'], $rprefs['urdd_port'], $userID);
            $update_msg = set_and_test_pref_array('period_update', 0, $pkeys);
            if ($update_msg == '' && isset($_POST['period_update']) && $_POST['period_update'] > 0) {
                $update_msg = set_and_test_pref_numeric('time1_update', 0, 0, 23);
                if ($update_msg == '') 
                    $update_msg = set_and_test_pref_numeric('time2_update', 0, 0, 59);
                if ($update_msg == '') {
                    process_schedule($uc, $_POST['period_update'], $_POST['time1_update'], $_POST['time2_update'], COMMAND_CHECK_VERSION, '', '');
                }
            } else {
                set_pref($db, 'time1_update', '', 0);
                set_pref($db, 'time2_update', '', 0);
                $uc->unschedule(get_command(COMMAND_CHECK_VERSION), '');
            }
            $sendinfo_msg = set_and_test_pref_array('period_sendinfo', 0, $pkeys);
            if ($sendinfo_msg == '' &&  isset($_POST['period_sendinfo']) && $_POST['period_sendinfo'] > 0) {
                $sendinfo_msg = set_and_test_pref_numeric('time1_sendinfo', 0, 0, 23);
                if ($sendinfo_msg == '')
                    $sendinfo_msg = set_and_test_pref_numeric('time2_sendinfo', 0, 0, 59);
                if ($sendinfo_msg == '') {
                    process_schedule($uc, $_POST['period_sendinfo'], $_POST['time1_sendinfo'], $_POST['time2_sendinfo'], COMMAND_SENDSETINFO, '', '');
                }
            } else {
                set_pref($db, 'time1_sendinfo', '', 0);
                set_pref($db, 'time2_sendinfo', '', 0);
                $uc->unschedule(get_command(COMMAND_SENDSETINFO), '');
            }
            $getinfo_msg = set_and_test_pref_array('period_getinfo', 0, $pkeys);
            if ($getinfo_msg == '' &&  isset($_POST['period_getinfo']) &&$_POST['period_getinfo'] > 0) {
                $getinfo_msg = set_and_test_pref_numeric('time1_getinfo', 0, 0, 23);
                if ($getinfo_msg == '')
                    $getinfo_msg = set_and_test_pref_numeric('time2_getinfo', 0, 0, 59);
                if ($getinfo_msg == '') {
                    process_schedule($uc, $_POST['period_getinfo'], $_POST['time1_getinfo'], $_POST['time2_getinfo'], COMMAND_GETSETINFO, '', '');
                }
            } else {
                set_pref($db, 'time1_getinfo', '', 0);
                set_pref($db, 'time2_getinfo', '', 0);
                $uc->unschedule(get_command(COMMAND_GETSETINFO), '');
            }

            $nglist_msg = set_and_test_pref_array('period_ng', 0, $pkeys);
            if ($nglist_msg == '' &&  isset($_POST['period_ng']) && $_POST['period_ng'] > 0) {
                $nglist_msg = set_and_test_pref_numeric('time1_ng', 0, 0, 23);
                if ($nglist_msg == '')
                    $nglist_msg = set_and_test_pref_numeric('time2_ng', 0, 0, 59);
                if ($nglist_msg == '') {
                    process_schedule($uc, $_POST['period_ng'], $_POST['time1_ng'], $_POST['time2_ng'], COMMAND_GROUPS, '', '');
                }
            } else {
                set_pref($db,'time1_ng', '', 0);
                set_pref($db,'time2_ng', '', 0);
                $uc->unschedule(get_command(COMMAND_GROUPS), '');
            }
            $cleandb = set_and_test_pref_array('period_cdb', 0, $pkeys);
            if ($cleandb == '' && isset( $_POST['period_cdb']) && $_POST['period_cdb'] > 0) {
                $cleandb_msg = set_and_test_pref_numeric('time1_cdb', 0, 0, 23);
                if ($cleandb_msg == '')
                    $cleandb_msg = set_and_test_pref_numeric('time2_cdb', 0, 0, 59);
                if ($cleandb_msg == '') {
                    process_schedule($uc, $_POST['period_cdb'], $_POST['time1_cdb'], $_POST['time2_cdb'], COMMAND_CLEANDB, '', '');
                }
            } else {
                set_pref($db, 'time1_cdb', '', 0);
                set_pref($db, 'time2_cdb', '', 0);
                $uc->unschedule(get_command(COMMAND_CLEANDB), '');
            }

            $cleandir_msg = set_and_test_pref_array('period_cd', 0, $pkeys);
            if ($cleandir_msg == '' && isset( $_POST['period_cd'] ) && $_POST['period_cd'] > 0) {
                $cleandir_msg = set_and_test_pref_numeric('time1_cd', 0, 0, 23);
                if ($cleandir_msg == '') 
                    $cleandir_msg = set_and_test_pref_numeric('time2_cd', 0, 0, 59);
                if ($cleandir_msg == '') 
                    $cleandir_msg = set_and_test_pref_array('dir_cd', 0, array_keys($cleandir_dirs));
                if ($cleandir_msg == '') {
                    process_schedule($uc, $_POST['period_cd'], $_POST['time1_cd'], $_POST['time2_cd'], COMMAND_CLEANDIR, '__all', $_POST['dir_cd']);
                }
            } else {
                set_pref($db, 'time1_cd', '', 0);
                set_pref($db, 'time2_cd', '', 0);
                $dir = $rprefs['dir_cd'];
                $uc->unschedule(get_command(COMMAND_CLEANDIR), "$dir");
            }
            $optimise_msg = set_and_test_pref_array('period_opt', 0, $pkeys);
            if ($optimise_msg == '' && isset($_POST['period_opt']) && $_POST['period_opt'] > 0) {
                $optimise_msg = set_and_test_pref_numeric('time1_opt',0, 0, 23);
                if ($optimise_msg === '') 
                    $optimise_msg = set_and_test_pref_numeric('time2_opt',0, 0, 59);
                if ($optimise_msg === '') {
                    process_schedule($uc, $_POST['period_opt'], $_POST['time1_opt'], $_POST['time2_opt'], COMMAND_OPTIMISE, '', '');
                }
            } else {
                set_pref($db, 'time1_opt', '', 0);
                set_pref($db, 'time2_opt', '', 0);
                $uc->unschedule(get_command(COMMAND_OPTIMISE), '');
                // unschedule update
            }
            $clean_dir_age_msg = set_and_test_pref_numeric('clean_dir_age', 0, 0);
            $clean_db_age_msg = set_and_test_pref_numeric('clean_db_age', 0, 0);
        } catch (exception $e) {
            $__message[] = 'Schedules could not be set!' . $e;
        }
    }
    $log_level_msg = set_and_test_pref_array('log_level', 0, array_keys($log_levels));
    if ($log_level_msg == '' && $URDDONLINE)
        $uc->set('log_level', $log_str[$_POST['log_level']]);

    $scheduler_msg = set_and_test_pref_array('scheduler', 0, array_keys($on_off));
    if ($log_level_msg == '' && $URDDONLINE) 
        $uc->set('scheduler', $_POST['scheduler']);

    $socket_timeout_msg = set_and_test_pref_numeric('socket_timeout', 0, 0);
    $forumusername_msg = set_and_test_pref_text('forumusername', 0, NULL, !isset ($_POST['forumpassword']) || $_POST['forumpassword'] == '');
    $forumpassword_msg = set_and_test_pref_text('forumpassword', 0, NULL, !isset ($_POST['forumusername']) || $_POST['forumusername'] == '');
    $index_page_msg = set_and_test_pref_array('index_page_root', 0, array_keys($index_page_array));
    $auto_login_msg = set_and_test_pref_array('auto_login', 0, array_keys($users));
    $admin_email_msg = set_and_test_pref_email('admin_email',0);
    $group_msg = set_and_test_pref_group('group',0, TRUE);
    $shaping_msg = set_and_test_pref_bool('shaping', 0, $shaping);
    $parse_nfo_msg = set_and_test_pref_bool('parse_nfo', 0, $parse_nfo);
    $sendmail_msg = set_and_test_pref_bool('sendmail', 0, $sendmail);
    $check_nntp_connections_msg = set_and_test_pref_bool('check_nntp_connections', 0, $check_nntp_connections);
    $auto_download_msg = set_and_test_pref_bool('auto_download', 0, $auto_download);
    $compress_nzb_msg = set_and_test_pref_bool('compress_nzb', 0, $compress_nzb);
    $webdownload_msg = set_and_test_pref_bool('webdownload', 0, $sendmail);
    $global_scripts_msg = set_and_test_pref_bool('allow_global_scripts', 0, $global_scripts);
    $user_scripts_msg = set_and_test_pref_bool('allow_user_scripts', 0, $user_scripts);
    $auto_expire_msg = set_and_test_pref_bool('auto_expire', 0, $foo);
    $urdd_restart_msg = set_and_test_pref_bool('urdd_restart', 0, $foo);
    $auto_reg_msg = set_and_test_pref_bool('auto_reg', 0, $foo);
    $register_msg = set_and_test_pref_bool('register', 0, $foo);
    $keep_int_msg = set_and_test_pref_bool('keep_interesting', 0, $foo);
    $default_template_msg = set_and_test_pref_array('default_template', 0, array_keys($templates));
    $default_language_msg = set_and_test_pref_array('default_language', 0, array_keys($languages));
    $permissions_msg = set_and_test_pref_array('permissions', 0, array_keys($permissions));
    // Check if it ends with a / :
    $dlpath = realpath($_POST['dlpath']);
    
    if (substr($dlpath,-1) != '/' ) 
        $dlpath .= '/';  
    $_POST['dlpath'] = $dlpath;
    $dlpath_msg = set_and_test_pref_dlpath('dlpath', 0);
    if ($shaping) {
        $maxdl_msg = set_and_test_pref_numeric('maxdl', 0, 0);
        $maxul_msg = set_and_test_pref_numeric('maxul', 0, 0);
    }
    $maxexpire_msg = set_and_test_pref_numeric('maxexpire', 0, 0);
    $maxfilesize_msg = set_and_test_pref_numeric('maxfilesize', 0, 0);
    $nice_value_msg = set_and_test_pref_numeric('nice_value', 0, 0,19);
    $total_max_articles_msg = set_and_test_pref_numeric('total_max_articles', 0, 0);
    $max_dl_name_msg = set_and_test_pref_numeric('max_dl_name', 0, 16);
    $hidden_files_list_msg = set_and_test_pref_text_area('global_hidden_files_list', 0, TRUE);
    $hiddenfiles_msg = set_and_test_pref_bool('global_hiddenfiles', 0, $foo);
    $urdd_path_msg = set_and_test_pref_prog('urdd_path', 0);
    $trickle_path_msg = set_and_test_pref_prog('trickle_path', 0, TRUE);
    $yydecode_path_msg = set_and_test_pref_prog('yydecode_path', 0);
    $yyencode_path_msg = set_and_test_pref_prog('yyencode_path', 0, TRUE);
    $cksfv_path_msg = set_and_test_pref_prog('cksfv_path', 0, TRUE);
    $unrar_path_msg = set_and_test_pref_prog('unrar_path', 0, TRUE);
    $rar_path_msg = set_and_test_pref_prog('rar_path', 0, TRUE);
    $unpar_path_msg = set_and_test_pref_prog('unpar_path', 0, TRUE); 
    $unace_path_msg = set_and_test_pref_prog('unace_path', 0, TRUE);
    $unzip_path_msg = set_and_test_pref_prog('unzip_path', 0, TRUE);
    $un7zr_path_msg = set_and_test_pref_prog('un7zr_path', 0, TRUE);
    $unarj_path_msg = set_and_test_pref_prog('unarj_path', 0, TRUE);
    $subdownloader_path_msg = set_and_test_pref_prog('subdownloader_path', 0, TRUE);
    $gzip_path_msg = set_and_test_pref_prog('gzip_path', 0, TRUE);
    $file_path_msg = set_and_test_pref_prog('file_path', 0, FALSE);
    $tar_path_msg = set_and_test_pref_prog('tar_path', 0, TRUE);
    $urdd_host_msg = set_and_test_pref_text('urdd_host', 0, '[a-zA-Z0-9.\-_:\[\]]');
    $replacement_str_msg = set_and_test_pref_text('replacement_str', 0, '[a-zA-Z0-9.\-_:\[\] ()!@#$%^&{}+;]', TRUE, TRUE);
    $url_msg = set_and_test_pref_url('url', 0);
    $urdd_port_msg = set_and_test_pref_numeric('urdd_port', 0, 1, 65535);
    $urdd_maxthreads_msg = set_and_test_pref_numeric('urdd_maxthreads', 0, 1);
    $nntp_maxthreads_msg = set_and_test_pref_numeric('nntp_maxthreads', 0, 1);
    $nntp_maxdlthreads_msg = set_and_test_pref_numeric('nntp_maxdlthreads', 0, 0);
    $db_intensive_maxthreads_msg = set_and_test_pref_numeric('db_intensive_maxthreads', 0, 0);
    $default_expire_time_msg = set_and_test_pref_numeric('default_expire_time', 0, 1);
    $expire_incomplete_msg = set_and_test_pref_numeric('expire_incomplete', 0, 0);
    $expire_percentage_msg = set_and_test_pref_numeric('expire_percentage', 0, 0, 100);
    $maxbuttons_msg = set_and_test_pref_numeric('maxbuttons', 0, 1);
    $urdd_pars_msg = set_and_test_pref_text('urdd_pars',0 , NULL, TRUE);
    $unpar_pars_msg = set_and_test_pref_text('unpar_pars',0 , NULL, TRUE);
    $unrar_pars_msg = set_and_test_pref_text('unrar_pars',0 , NULL, TRUE);
    $rar_pars_msg = set_and_test_pref_text('rar_pars',0 , NULL, TRUE);
    $unace_pars_msg = set_and_test_pref_text('unace_pars',0 , NULL, TRUE);
    $un7zr_pars_msg = set_and_test_pref_text('un7zr_pars',0 , NULL, TRUE);
    $unzip_pars_msg = set_and_test_pref_text('unzip_pars',0 , NULL, TRUE);
    $unarj_pars_msg = set_and_test_pref_text('unarj_pars',0 , NULL, TRUE);
    $subdownloader_pars_msg = set_and_test_pref_text('subdownloader_pars',0 , NULL, TRUE);
    $gzip_pars_msg = set_and_test_pref_text('gzip_pars',0 , NULL, TRUE);
    $yyencode_pars_msg = set_and_test_pref_text('yyencode_pars',0 , NULL, TRUE);
    $yydecode_pars_msg = set_and_test_pref_text('yydecode_pars',0 , NULL, TRUE);

    foreach ($SETTYPES as $t) 
        $settype_msg[$t] = set_and_test_pref_text("settype_$t", 0, NULL, TRUE);

    $saved = 1;

} else if (isset($_POST['reset'])) {
    verify_challenge($_POST['challenge']);
    /* Reset config */
    $uc = new urdd_client($rprefs['urdd_host'],$rprefs['urdd_port'],$userID);
    $old_dir = $rprefs['dir_cd'];
    $uc->unschedule(get_command(COMMAND_CLEANDIR), '__all');
    $uc->unschedule(get_command(COMMAND_CLEANDB), '');
    $uc->unschedule(get_command(COMMAND_CHECK_VERSION), '');
    $uc->unschedule(get_command(COMMAND_GROUPS), '');
    $uc->unschedule(get_command(COMMAND_OPTIMISE), '');
    $uc->unschedule(get_command(COMMAND_GETSETINFO), '');
    $uc->unschedule(get_command(COMMAND_SENDSETINFO), '');

    reset_config($db);
}

/* Get all current settings and do sanity check: */
$prefArray_root = get_default_config();
$prefArray_root = array_merge($prefArray_root,load_config($db));

foreach ($SETTYPES as $t) {
    if (!isset($settype_msg[$t]))
        $settype_msg[$t] = verify_text($prefArray_root["settype_$t"]);
}

if (!isset($index_page_msg))
    $index_page_msg = verify_array($prefArray_root['index_page_root'], array_keys($index_page_array));
if (!isset($group_msg))
    $group_msg = verify_group($prefArray_root['group'], TRUE);
if (!isset($permissions_msg))
    $permissions_msg = verify_array($prefArray_root['permissions'], array_keys($permissions));
if (!isset($log_level_msg))
    $log_level_msg = verify_array($prefArray_root['log_level'], array_keys($log_levels));
if (!isset($scheduler_msg))
    $scheduler_msg = verify_array($prefArray_root['scheduler'], array_keys($on_off));
if (!isset($hidden_files_list_msg))
    $hidden_files_list_msg = verify_text_area($prefArray_root['global_hidden_files_list']);
if (!isset($url_msg))
    $url_msg = verify_url($prefArray_root['url']);
if (!isset($admin_email_msg))
    $admin_email_msg = verify_email_address($prefArray_root['admin_email']);
if (!isset($unrar_path_msg))
    $unrar_path_msg = verify_prog($prefArray_root['unrar_path'], TRUE);
if (!isset($rar_path_msg))
    $rar_path_msg = verify_prog($prefArray_root['rar_path'], TRUE);
if (!isset($unarj_path_msg))
    $unarj_path_msg = verify_prog($prefArray_root['unarj_path'], TRUE);
if (!isset($subdownloader_path_msg))
    $subdownloader_path_msg = verify_prog($prefArray_root['subdownloader_path'], TRUE);
if (!isset($file_path_msg))
    $file_path_msg = verify_prog($prefArray_root['file_path'], TRUE);
if (!isset($tar_path_msg))
    $tar_path_msg = verify_prog($prefArray_root['tar_path'], TRUE);
if (!isset($gzip_path_msg))
    $gzip_path_msg = verify_prog($prefArray_root['gzip_path'], TRUE);
if (!isset($unzip_path_msg))
    $unzip_path_msg = verify_prog($prefArray_root['unzip_path'], TRUE);
if (!isset($un7zr_path_msg))
    $un7zr_path_msg = verify_prog($prefArray_root['un7zr_path'], TRUE);
if (!isset($unace_path_msg))
    $unace_path_msg = verify_prog($prefArray_root['unace_path'], TRUE);
if (!isset($unpar_path_msg))
    $unpar_path_msg = verify_prog($prefArray_root['unpar_path'], TRUE);
if (!isset($yydecode_path_msg))
    $yydecode_path_msg= verify_prog($prefArray_root['yydecode_path']);
if (!isset($yyencode_path_msg))
    $yyencode_path_msg= verify_prog($prefArray_root['yyencode_path'], TRUE);
if (!isset($urdd_path_msg))
    $urdd_path_msg = verify_prog($prefArray_root['urdd_path']);
if (!isset($cksfv_path_msg))
    $cksfv_path_msg = verify_prog($prefArray_root['cksfv_path'], TRUE);
if (!isset($trickle_path_msg))
    $trickle_path_msg = verify_prog($prefArray_root['trickle_path'], TRUE);
if (!isset($urdd_maxthreads_msg))
    $urdd_maxthreads_msg = verify_numeric($prefArray_root['urdd_maxthreads'], 1);
if (!isset($nntp_maxdlthreads_msg))
    $nntp_maxdlthreads_msg = verify_numeric($prefArray_root['nntp_maxdlthreads'], 0);
if (!isset($clean_dir_age_msg))
    $clean_dir_age_msg = verify_numeric($prefArray_root['clean_dir_age'], 0);
if (!isset($max_dl_name_msg))
    $max_dl_name_msg = verify_numeric($prefArray_root['max_dl_name'], 16);
if (!isset($clean_db_age_msg))
    $clean_db_age_msg = verify_numeric($prefArray_root['clean_db_age'], 0);
if (!isset($nntp_maxthreads_msg))
    $nntp_maxthreads_msg = verify_numeric($prefArray_root['nntp_maxthreads'], 1);
if (!isset($db_intensive_maxthreads_msg))
    $db_intensive_maxthreads_msg = verify_numeric($prefArray_root['db_intensive_maxthreads'], 1);
if (!isset($maxfilesize_msg))
    $maxfilesize_msg = verify_numeric($prefArray_root['maxfilesize'], 0);
if (!isset($maxexpire_msg))
    $maxexpire_msg = verify_numeric($prefArray_root['maxexpire'], 0);
if (!isset($socket_timeout_msg))
    $socket_timeout_msg = verify_numeric($prefArray_root['socket_timeout'], 0);
if (!isset($total_max_articles_msg))
    $total_max_articles_msg = verify_numeric($prefArray_root['total_max_articles'], 0);
if (!isset($nice_value_msg))
    $nice_value_msg = verify_numeric($prefArray_root['nice_value'], 0, 19);
if (!isset($urdd_port_msg))
    $urdd_port_msg = verify_numeric($prefArray_root['urdd_port'], 1, 65535);
if (!isset($urdd_host_msg))
    $urdd_host_msg = verify_text($prefArray_root['urdd_host'], '[a-zA-Z0-9.\-_:\[\]]');
if (!isset($replacement_str_msg))
    $replacement_str_msg = verify_text_opt($prefArray_root['replacement_str'], 0, '[a-zA-Z0-9.\-_:\[\] ()!@#$%^&{}+;]');
if (!isset($dlpath_msg))
    $dlpath_msg = verify_dlpath($db, $prefArray_root['dlpath']);
if (!isset($maxdl_msg))
    $maxdl_msg = verify_numeric($prefArray_root['maxdl'], 0);
if (!isset($maxul_msg))
    $maxul_msg = verify_numeric($prefArray_root['maxul'], 0);
if (!isset($default_expire_time_msg))
    $default_expire_time_msg = verify_numeric($prefArray_root['default_expire_time'], 1);
if (!isset($expire_incomplete_msg))
    $expire_incomplete_msg = verify_numeric($prefArray_root['expire_incomplete'], 0);
if (!isset($expire_percentage_msg))
    $expire_percentage_msg = verify_numeric($prefArray_root['expire_percentage'], 0, 100);
if (!isset($default_language_msg))
    $default_language_msg = verify_array($prefArray_root['default_language'], array_keys($languages));
if (!isset($auto_login_msg))
    $auto_login_msg = verify_array($prefArray_root['auto_login'], array_keys($users));
if (!isset($default_template_msg))
    $default_template_msg = verify_array($prefArray_root['default_template'], array_keys($templates));
if (!isset($forumusername_msg))
    $forumusername_msg = verify_text_opt($prefArray_root['forumusername'], $prefArray_root['forumpassword'] != '', NULL);
if (!isset($forumpassword_msg))
    $forumpassword_msg = verify_text_opt($prefArray_root['forumpassword'], $prefArray_root['forumusername'] != '', NULL);
if (!isset($maxbuttons_msg))
    $maxbuttons_msg = verify_numeric($prefArray_root['maxbuttons'],0);
if (!isset($update_msg))
    $update_msg = verify_array($prefArray_root['period_update'], array_keys($periods->periods));
if ($prefArray_root['period_update'] > 0) {
    if (!isset($update_msg)) {
        $update_msg = verify_numeric($prefArray_root['time1_update'],0, 23);
        $update_msg .= verify_numeric($prefArray_root['time2_update'], 0,59);
    }
} else
    $update_msg = '';
if ($prefArray_root['period_sendinfo'] > 0) {
    if (!isset($sendinfo_msg)) {
        $sendinfo_msg = verify_numeric($prefArray_root['time1_sendinfo'],0, 23);
        $sendinfo_msg .= verify_numeric($prefArray_root['time2_sendinfo'], 0,59);
    }
} else 
    $sendinfo_msg = '';
if ($prefArray_root['period_getinfo'] > 0) {
    if (!isset($getinfo_msg)) {
        $getinfo_msg = verify_numeric($prefArray_root['time1_getinfo'],0, 23);
        $getinfo_msg .= verify_numeric($prefArray_root['time2_getinfo'], 0,59);
    }
} else 
    $getinfo_msg = '';

if (!isset($nglist_msg))
    $nglist_msg = verify_array($prefArray_root['period_ng'], array_keys($periods->periods));
if ($prefArray_root['period_ng'] > 0) {
    if (!isset($nglist_msg)) {
        $nglist_msg .= verify_numeric($prefArray_root['time1_ng'],0, 23);
        $nglist_msg .= verify_numeric($prefArray_root['time2_ng'], 0,59);
    }
} else 
    $nglist_msg = '';
if (!isset($cleandb_msg))
    $cleandb_msg = verify_array($prefArray_root['period_cdb'], array_keys($periods->periods));
if ($prefArray_root['period_cdb'] > 0) {
    if (!isset($cleandb_msg)) {
        $cleandb_msg = verify_numeric($prefArray_root['time1_cdb'],0, 23);
        $cleandb_msg .= verify_numeric($prefArray_root['time2_cdb'], 0,59);
    }
} else 
    $cleandb_msg = '';

if (!isset($cleandir_msg))
    $cleandir_msg = verify_array($prefArray_root['period_cd'], array_keys($periods->periods));
if ($prefArray_root['period_cd'] > 0) {
    if (!isset($cleandir_msg)) {
        $cleandir_msg = verify_numeric($prefArray_root['time1_cd'],0, 23);
        $cleandir_msg .= verify_numeric($prefArray_root['time2_cd'], 0,59);
        $cleandir_msg .= verify_array($prefArray_root['dir_cd'], 0, array_keys($cleandir_dirs));
    }
} else 
    $cleandir_msg = '';
if (!isset($optimise_msg))
    $optimise_msg = verify_array($prefArray_root['period_opt'], array_keys($periods->periods));
if ($prefArray_root['period_opt'] > 0) {
    if (!isset($optimise_msg)) {
        $optimise_msg = verify_numeric($prefArray_root['time1_opt'],0, 23);
        $optimise_msg .= verify_numeric($prefArray_root['time2_opt'], 0,59);
    }
} else 
    $optimise_msg = '';

if (!isset($urdd_pars_msg))
    $urdd_pars_msg = verify_text_opt('urdd_pars', TRUE, NULL);
if (!isset($unpar_pars_msg))
    $unpar_pars_msg = verify_text_opt('unpar_pars', TRUE, NULL);
if (!isset($unrar_pars_msg)) 
    $unrar_pars_msg = verify_text_opt('unrar_pars', TRUE, NULL);
if (!isset($rar_pars_msg)) 
    $rar_pars_msg = verify_text_opt('rar_pars', TRUE, NULL);
if (!isset($unace_pars_msg)) 
    $unace_pars_msg = verify_text_opt('unace_pars', TRUE, NULL);
if (!isset($un7zr_pars_msg)) 
    $un7zr_pars_msg = verify_text_opt('un7zr_pars', TRUE, NULL);
if (!isset($unzip_pars_msg ))
    $unzip_pars_msg = verify_text_opt('unzip_pars', TRUE, NULL);
if (!isset($gzip_pars_msg ))
    $gzip_pars_msg = verify_text_opt('gzip_pars', TRUE, NULL);
if (!isset($unarj_pars_msg)) 
    $unarj_pars_msg = verify_text_opt('unarj_pars', TRUE, NULL);
if (!isset($subdownloader_pars_msg)) 
    $subdownloader_pars_msg = verify_text_opt('subdownloader_pars', TRUE, NULL);
if (!isset($yydecode_pars_msg)) 
    $yydecode_pars_msg = verify_text_opt('yydecode_pars', TRUE, NULL);
if (!isset($yyencode_pars_msg)) 
    $yyencode_pars_msg = verify_text_opt('yyencode_pars', TRUE, NULL);


$hidden_files_list = $prefArray_root['global_hidden_files_list'];
$hidden_files_list = str_replace('\n', "\n", $hidden_files_list);
$hidden_files_list = str_replace('\r', '', $hidden_files_list);
$hidden_files_list = clean_list($hidden_files_list);


$urdd_cfg = array (
    new pref_text (CONFIG_LEVEL_BASIC, $LN['config_max_threads'], 'urdd_maxthreads', $LN['config_max_threads_msg'], $urdd_maxthreads_msg, $prefArray_root['urdd_maxthreads'], NUMBER_BOX_SIZE), 
    new pref_text (CONFIG_LEVEL_BASIC, $LN['config_max_nntp'], 'nntp_maxthreads', $LN['config_max_nntp_msg'], $nntp_maxthreads_msg, $prefArray_root['nntp_maxthreads'], NUMBER_BOX_SIZE), 
    new pref_text (CONFIG_LEVEL_ADVANCED, $LN['config_max_dlnntp'], 'nntp_maxdlthreads', $LN['config_max_dlnntp_msg'], $nntp_maxdlthreads_msg, $prefArray_root['nntp_maxdlthreads'], NUMBER_BOX_SIZE), 
    new pref_text (CONFIG_LEVEL_MASTER, $LN['config_max_db_intensive'], 'db_intensive_maxthreads', $LN['config_max_db_intensive_msg'], $db_intensive_maxthreads_msg, $prefArray_root['db_intensive_maxthreads'], NUMBER_BOX_SIZE), 
    new pref_checkbox (CONFIG_LEVEL_ADVANCED, $LN['config_check_nntp_connections'], 'check_nntp_connections', $LN['config_check_nntp_connections_msg'], $check_nntp_connections_msg, $prefArray_root['check_nntp_connections']),
    new pref_text (CONFIG_LEVEL_ADVANCED, $LN['config_socket_timeout'], 'socket_timeout', $LN['config_socket_timeout_msg'], $socket_timeout_msg, $prefArray_root['socket_timeout'], NUMBER_BOX_SIZE), 
    new pref_text (CONFIG_LEVEL_ADVANCED, $LN['config_total_max_articles'], 'total_max_articles', $LN['config_total_max_articles_msg'], $total_max_articles_msg, $prefArray_root['total_max_articles'], NUMBER_BOX_SIZE), 
    new pref_text (CONFIG_LEVEL_ADVANCED, $LN['config_expire'], 'default_expire_time', $LN['config_expire_msg'], $default_expire_time_msg, $prefArray_root['default_expire_time'], NUMBER_BOX_SIZE),
    new pref_text (CONFIG_LEVEL_ADVANCED, $LN['config_expire_incomplete'], 'expire_incomplete', $LN['config_expire_incomplete_msg'], $expire_incomplete_msg, $prefArray_root['expire_incomplete'], NUMBER_BOX_SIZE),
    new pref_text (CONFIG_LEVEL_ADVANCED, $LN['config_expire_percentage'], 'expire_percentage', $LN['config_expire_percentage_msg'], $expire_percentage_msg, $prefArray_root['expire_percentage'], NUMBER_BOX_SIZE),
    new pref_checkbox (CONFIG_LEVEL_BASIC, $LN['config_expafterupdate'], 'auto_expire', $LN['config_expafterupdate_msg'], $auto_expire_msg, $prefArray_root['auto_expire']),
    new pref_text (CONFIG_LEVEL_BASIC, $LN['config_dlpath'], 'dlpath', $LN['config_dlpath_msg'], $dlpath_msg , $prefArray_root['dlpath'], TEXT_BOX_SIZE),
    new pref_text (CONFIG_LEVEL_BASIC, $LN['config_urddhostname'], 'urdd_host', $LN['config_urddhostname_msg'], $urdd_host_msg, $prefArray_root['urdd_host'], TEXT_BOX_SIZE),
    new pref_text (CONFIG_LEVEL_ADVANCED, $LN['config_urddport'], 'urdd_port', $LN['config_urddport_msg'], $urdd_port_msg, $prefArray_root['urdd_port'], NUMBER_BOX_SIZE),
    new pref_checkbox (CONFIG_LEVEL_ADVANCED, $LN['config_restart'], 'urdd_restart', $LN['config_restart_msg'], $urdd_restart_msg, $prefArray_root['urdd_restart']),
    new pref_select (CONFIG_LEVEL_MASTER, $LN['config_scheduler'], 'scheduler', $LN['config_scheduler_msg'], $scheduler_msg, $on_off, $prefArray_root['scheduler']),
    new pref_text (CONFIG_LEVEL_MASTER, $LN['config_max_dl_name'], 'max_dl_name', $LN['config_max_dl_name_msg'], $max_dl_name_msg, $prefArray_root['max_dl_name'], NUMBER_BOX_SIZE),
    new pref_text (CONFIG_LEVEL_MASTER, $LN['config_nice_value'], 'nice_value', $LN['config_nice_value_msg'], $nice_value_msg, $prefArray_root['nice_value'], NUMBER_BOX_SIZE) 
);

$networking = array(
    new pref_text (CONFIG_LEVEL_BASIC, $LN['config_adminemail'], 'admin_email', $LN['config_adminemail_msg'], $admin_email_msg, $prefArray_root['admin_email'], TEXT_BOX_SIZE),
    new pref_text (CONFIG_LEVEL_BASIC, $LN['config_baseurl'], 'url', $LN['config_baseurl_msg'],$url_msg, $prefArray_root['url'], TEXT_BOX_SIZE),
    new pref_checkbox (CONFIG_LEVEL_MASTER, $LN['config_shaping'], 'shaping', $LN['config_shaping_msg'], $shaping_msg , $prefArray_root['shaping'], 'onclick="javascript:toggle_hide(\'shaping1\', \'hidden\'); toggle_hide(\'shaping2\', \'hidden\')"'),
    new pref_text (CONFIG_LEVEL_MASTER, $LN['config_maxdl'], 'maxdl', $LN['config_maxdl_msg'],$maxdl_msg, $prefArray_root['maxdl'], NUMBER_BOX_SIZE, NULL, 'shaping1', $prefArray_root['shaping']?NULL: 'hidden'),
    new pref_text (CONFIG_LEVEL_MASTER, $LN['config_maxul'], 'maxul', $LN['config_maxul_msg'],$maxul_msg, $prefArray_root['maxul'], NUMBER_BOX_SIZE, NULL, 'shaping2', $prefArray_root['shaping']?NULL: 'hidden'),
    new pref_checkbox (CONFIG_LEVEL_ADVANCED, $LN['config_register'], 'register', $LN['config_register_msg'],$register_msg,  $prefArray_root['register'], 'onclick="javascript:toggle_hide(\'auto_reg\', \'hidden\'); toggle_value(\'register\')"'),
    new pref_checkbox (CONFIG_LEVEL_ADVANCED, $LN['config_autoaccept'], 'auto_reg', $LN['config_autoaccept_msg'], $auto_reg_msg, $prefArray_root['auto_reg'], NULL, 'auto_reg', $prefArray_root['register']?'':'hidden')
); 

$ext_progs = array(
    new pref_text (CONFIG_LEVEL_BASIC, $LN['config_urdd'], 'urdd_path', $LN['config_urdd_msg'], $urdd_path_msg, $prefArray_root['urdd_path'], TEXT_BOX_SIZE),
    new pref_text (CONFIG_LEVEL_BASIC, $LN['config_yydecode'], 'yydecode_path', $LN['config_yydecode_msg'], $yydecode_path_msg , $prefArray_root['yydecode_path'], TEXT_BOX_SIZE),
    new pref_text (CONFIG_LEVEL_BASIC, $LN['config_yyencode'], 'yyencode_path', $LN['config_yyencode_msg'], $yyencode_path_msg , $prefArray_root['yyencode_path'], TEXT_BOX_SIZE),
    new pref_text (CONFIG_LEVEL_BASIC, $LN['config_par2'], 'unpar_path', $LN['config_par2_msg'], $unpar_path_msg,  $prefArray_root['unpar_path'], TEXT_BOX_SIZE),
    new pref_text (CONFIG_LEVEL_BASIC, $LN['config_unrar'], 'unrar_path', $LN['config_unrar_msg'], $unrar_path_msg,  $prefArray_root['unrar_path'], TEXT_BOX_SIZE),
    new pref_text (CONFIG_LEVEL_BASIC, $LN['config_rar'], 'rar_path', $LN['config_rar_msg'], $rar_path_msg,  $prefArray_root['rar_path'], TEXT_BOX_SIZE),
    new pref_text (CONFIG_LEVEL_ADVANCED, $LN['config_unace'], 'unace_path', $LN['config_unace_msg'], $unace_path_msg, $prefArray_root['unace_path'], TEXT_BOX_SIZE),
    new pref_text (CONFIG_LEVEL_ADVANCED, $LN['config_un7zr'], 'un7zr_path', $LN['config_un7zr_msg'], $un7zr_path_msg, $prefArray_root['un7zr_path'], TEXT_BOX_SIZE),
    new pref_text (CONFIG_LEVEL_ADVANCED, $LN['config_unzip'], 'unzip_path', $LN['config_unzip_msg'], $unzip_path_msg, $prefArray_root['unzip_path'], TEXT_BOX_SIZE),
    new pref_text (CONFIG_LEVEL_ADVANCED, $LN['config_gzip'], 'gzip_path', $LN['config_gzip_msg'], $gzip_path_msg, $prefArray_root['gzip_path'], TEXT_BOX_SIZE),
    new pref_text (CONFIG_LEVEL_ADVANCED, $LN['config_unarj'], 'unarj_path', $LN['config_unarj_msg'], $unarj_path_msg, $prefArray_root['unarj_path'], TEXT_BOX_SIZE),
    new pref_text (CONFIG_LEVEL_ADVANCED, $LN['config_file'], 'file_path', $LN['config_file_msg'], $file_path_msg, $prefArray_root['file_path'], TEXT_BOX_SIZE),
    new pref_text (CONFIG_LEVEL_ADVANCED, $LN['config_tar'], 'tar_path', $LN['config_tar_msg'], $tar_path_msg, $prefArray_root['tar_path'], TEXT_BOX_SIZE),
    new pref_text (CONFIG_LEVEL_ADVANCED, $LN['config_cksfv'], 'cksfv_path', $LN['config_cksfv_msg'], $cksfv_path_msg,  $prefArray_root['cksfv_path'], TEXT_BOX_SIZE),
    new pref_text (CONFIG_LEVEL_MASTER, $LN['config_trickle'], 'trickle_path', $LN['config_trickle_msg'], $trickle_path_msg, $prefArray_root['trickle_path'], TEXT_BOX_SIZE), 
    new pref_text (CONFIG_LEVEL_MASTER, $LN['config_subdownloader'], 'subdownloader_path', $LN['config_subdownloader_msg'], $subdownloader_path_msg, $prefArray_root['subdownloader_path'], TEXT_BOX_SIZE) 
);
$prog_params = array(
    new pref_text (CONFIG_LEVEL_MASTER, $LN['config_urdd_pars'], 'urdd_pars', $LN['config_urdd_pars_msg'], $urdd_pars_msg, $prefArray_root['urdd_pars'], TEXT_BOX_SIZE),
    new pref_text (CONFIG_LEVEL_MASTER, $LN['config_yydecode_pars'], 'yydecode_pars', $LN['config_yydecode_pars_msg'], $yydecode_pars_msg,  $prefArray_root['yydecode_pars'], TEXT_BOX_SIZE),
    new pref_text (CONFIG_LEVEL_MASTER, $LN['config_yyencode_pars'], 'yyencode_pars', $LN['config_yyencode_pars_msg'], $yyencode_pars_msg,  $prefArray_root['yyencode_pars'], TEXT_BOX_SIZE),
    new pref_text (CONFIG_LEVEL_MASTER, $LN['config_par2_pars'], 'unpar_pars', $LN['config_par2_pars_msg'], $unpar_pars_msg, $prefArray_root['unpar_pars'], TEXT_BOX_SIZE),
    new pref_text (CONFIG_LEVEL_MASTER, $LN['config_unrar_pars'], 'unrar_pars', $LN['config_unrar_pars_msg'], $unrar_pars_msg, $prefArray_root['unrar_pars'], TEXT_BOX_SIZE),
    new pref_text (CONFIG_LEVEL_MASTER, $LN['config_rar_pars'], 'rar_pars', $LN['config_rar_pars_msg'], $rar_pars_msg, $prefArray_root['rar_pars'], TEXT_BOX_SIZE),
    new pref_text (CONFIG_LEVEL_MASTER, $LN['config_unace_pars'], 'unace_pars', $LN['config_unace_pars_msg'], $unace_pars_msg, $prefArray_root['unace_pars'], TEXT_BOX_SIZE),
    new pref_text (CONFIG_LEVEL_MASTER, $LN['config_un7zr_pars'], 'un7zr_pars', $LN['config_un7zr_pars_msg'], $un7zr_pars_msg, $prefArray_root['un7zr_pars'], TEXT_BOX_SIZE),
    new pref_text (CONFIG_LEVEL_MASTER, $LN['config_unzip_pars'], 'unzip_pars', $LN['config_unzip_pars_msg'], $unzip_pars_msg, $prefArray_root['unzip_pars'], TEXT_BOX_SIZE),
    new pref_text (CONFIG_LEVEL_MASTER, $LN['config_gzip_pars'], 'gzip_pars', $LN['config_gzip_pars_msg'], $gzip_pars_msg, $prefArray_root['gzip_pars'], TEXT_BOX_SIZE),
    new pref_text (CONFIG_LEVEL_MASTER, $LN['config_unarj_pars'], 'unarj_pars', $LN['config_unarj_pars_msg'], $unarj_pars_msg, $prefArray_root['unarj_pars'], TEXT_BOX_SIZE),
    new pref_text (CONFIG_LEVEL_MASTER, $LN['config_subdownloader_pars'], 'subdownloader_pars', $LN['config_subdownloader_pars_msg'], $unarj_pars_msg, $prefArray_root['subdownloader_pars'], TEXT_BOX_SIZE),
);


$maintenance_offline = array(
	new pref_plain(CONFIG_LEVEL_BASIC, $LN['urdddisabled'], $LN['urdddisabled'], $LN['enableurddfirst'], NULL, NULL),
    );
$maintenance = array(
    new pref_period (CONFIG_LEVEL_BASIC, $LN['config_checkupdate'], $LN['config_checkupdate_msg'], $update_msg, 'period_update', $prefArray_root['period_update'], 'time1_update', $prefArray_root['time1_update'], 'time2_update',$prefArray_root['time2_update']),
    new pref_period (CONFIG_LEVEL_BASIC, $LN['config_optimisedb'], $LN['config_optimisedb_msg'], $optimise_msg, 'period_opt', $prefArray_root['period_opt'], 'time1_opt', $prefArray_root['time1_opt'], 'time2_opt',$prefArray_root['time2_opt']),
    new pref_period (CONFIG_LEVEL_BASIC, $LN['config_updatenglist'], $LN['config_updatenglist_msg'], $nglist_msg,'period_ng', $prefArray_root['period_ng'], 'time1_ng', $prefArray_root['time1_ng'], 'time2_ng',$prefArray_root['time2_ng']),
    new pref_period (CONFIG_LEVEL_BASIC, $LN['config_cleandir'], $LN['config_cleandir_msg'], $cleandir_msg,  'period_cd', $prefArray_root['period_cd'], 'time1_cd', $prefArray_root['time1_cd'], 'time2_cd',$prefArray_root['time2_cd'], 'dir_cd',$cleandir_dirs, $prefArray_root['dir_cd']),
    new pref_text (CONFIG_LEVEL_ADVANCED, $LN['config_clean_dir_age'],'clean_dir_age', $LN['config_clean_dir_age_msg'], $clean_dir_age_msg, $prefArray_root['clean_dir_age'], NUMBER_BOX_SIZE), 
    new pref_period (CONFIG_LEVEL_BASIC, $LN['config_cleandb'], $LN['config_cleandb_msg'], $cleandb_msg, 'period_cdb', $prefArray_root['period_cdb'], 'time1_cdb', $prefArray_root['time1_cdb'], 'time2_cdb',$prefArray_root['time2_cdb']),
    new pref_text (CONFIG_LEVEL_ADVANCED, $LN['config_clean_db_age'],'clean_db_age', $LN['config_clean_db_age_msg'], $clean_db_age_msg, $prefArray_root['clean_db_age'], NUMBER_BOX_SIZE), 
    new pref_period (CONFIG_LEVEL_BASIC, $LN['config_sendinfo'], $LN['config_sendinfo_msg'], $sendinfo_msg, 'period_sendinfo', $prefArray_root['period_sendinfo'], 'time1_sendinfo', $prefArray_root['time1_sendinfo'], 'time2_sendinfo',$prefArray_root['time2_sendinfo']),
    new pref_period (CONFIG_LEVEL_BASIC, $LN['config_getinfo'], $LN['config_getinfo_msg'], $getinfo_msg, 'period_getinfo', $prefArray_root['period_getinfo'], 'time1_getinfo', $prefArray_root['time1_getinfo'], 'time2_getinfo',$prefArray_root['time2_getinfo'])

);

$global_settings = array(
	new pref_select (CONFIG_LEVEL_ALWAYS, $LN['pref_level'], 'pref_level', $LN['pref_level_msg'] ,'', $levels, $pref_level, 'onchange="javascript:submit_config()"'),
    new pref_select (CONFIG_LEVEL_BASIC, $LN['config_log_level'], 'log_level', $LN['config_log_level_msg'], $log_level_msg,  $log_levels, $prefArray_root['log_level']),
    new pref_checkbox (CONFIG_LEVEL_ADVANCED, $LN['config_keep_int'], 'keep_interesting', $LN['config_keep_int_msg'], $keep_int_msg, $prefArray_root['keep_interesting']),
    new pref_select (CONFIG_LEVEL_ADVANCED, $LN['config_permissions'], 'permissions', $LN['config_permissions_msg'], $permissions_msg,  $permissions, $prefArray_root['permissions']),
    new pref_select (CONFIG_LEVEL_ADVANCED, $LN['config_group'], 'group', $LN['config_group_msg'], $group_msg,  $groups, $prefArray_root['group']),
    new pref_select (CONFIG_LEVEL_ADVANCED, $LN['config_defaulttemplate'], 'default_template', $LN['config_defaulttemplate_msg'], $default_template_msg,  $templates, $prefArray_root['default_template']),
    new pref_select (CONFIG_LEVEL_BASIC, $LN['config_defaultlanguage'], 'default_language', $LN['config_defaultlanguage_msg'], $default_language_msg,  $languages, $prefArray_root['default_language']),
    new pref_select (CONFIG_LEVEL_BASIC, $LN['pref_index_page'], 'index_page_root', $LN['pref_index_page_msg'], $index_page_msg, $index_page_array, $prefArray_root['index_page_root']),

    new pref_text (CONFIG_LEVEL_MASTER, $LN['config_maxexpire'],'maxexpire', $LN['config_maxexpire_msg'], $maxexpire_msg, $prefArray_root['maxexpire'], NUMBER_BOX_SIZE), 
    new pref_text (CONFIG_LEVEL_MASTER, $LN['config_maxbuttons'], 'maxbuttons',$LN['config_maxbuttons_msg'] ,$maxbuttons_msg ,$prefArray_root['maxbuttons'], NUMBER_BOX_SIZE ),
    new pref_checkbox (CONFIG_LEVEL_ADVANCED, $LN['config_global_scripts'], 'allow_global_scripts', $LN['config_global_scripts_msg'], $global_scripts_msg, $prefArray_root['allow_global_scripts'], 'onclick="javascript:toggle_hide(\'hide_userscripts\', \'hidden\')"'),
    new pref_checkbox (CONFIG_LEVEL_ADVANCED, $LN['config_user_scripts'], 'allow_user_scripts', $LN['config_user_scripts_msg'], $user_scripts_msg, $prefArray_root['allow_user_scripts'], NULL, 'hide_userscripts', $prefArray_root['allow_global_scripts'] == 1?NULL: 'hidden'),
    new pref_checkbox (CONFIG_LEVEL_BASIC, $LN['config_webdownload'], 'webdownload', $LN['config_webdownload_msg'], $webdownload_msg, $prefArray_root['webdownload']),
    new pref_checkbox (CONFIG_LEVEL_BASIC, $LN['config_sendmail'], 'sendmail', $LN['config_sendmail_msg'], $sendmail_msg, $prefArray_root['sendmail']),
    new pref_checkbox (CONFIG_LEVEL_MASTER, $LN['config_parse_nfo'], 'parse_nfo', $LN['config_parse_nfo_msg'], $parse_nfo_msg, $prefArray_root['parse_nfo']),
    new pref_checkbox (CONFIG_LEVEL_BASIC, $LN['config_auto_download'], 'auto_download', $LN['config_auto_download_msg'], $auto_download_msg, $prefArray_root['auto_download']),
    new pref_select (CONFIG_LEVEL_MASTER, $LN['config_auto_login'], 'auto_login', $LN['config_auto_login_msg'], $auto_login_msg,  $users, $prefArray_root['auto_login']),
    new pref_checkbox (CONFIG_LEVEL_ADVANCED, $LN['hiddenfiles'], 'global_hiddenfiles',$LN['hiddenfiles_msg'], $hiddenfiles_msg, $prefArray_root['global_hiddenfiles'], 'onclick="javascript:toggle_hide(\'hidfil\', \'hidden\')"'),
    new pref_textarea (CONFIG_LEVEL_ADVANCED, $LN['hidden_files_list'], 'global_hidden_files_list',$LN['hidden_files_list_msg'], $hidden_files_list_msg ,$hidden_files_list,10,40 , NULL, 'hidfil', $prefArray_root['global_hiddenfiles']?NULL: 'hidden'),
    new pref_checkbox (CONFIG_LEVEL_ADVANCED, $LN['config_compress_nzb'],  'compress_nzb', $LN['config_compress_nzb_msg'], $compress_nzb_msg, $prefArray_root['compress_nzb']),
    new pref_text (CONFIG_LEVEL_ADVANCED, $LN['config_replacement_str'],  'replacement_str', $LN['config_replacement_str_msg'], $replacement_str_msg, $prefArray_root['replacement_str'], TEXT_BOX_SIZE)
);
$set_updating = array(
    new pref_text (CONFIG_LEVEL_BASIC, $LN['forumusername'], 'forumusername', $LN['forumusername_msg'], $forumusername_msg, $prefArray_root['forumusername'], TEXT_BOX_SIZE),
    new pref_password (CONFIG_LEVEL_BASIC, $LN['forumpassword'], 'forumpassword', $LN['forumpassword_msg'], $forumpassword_msg,  $prefArray_root['forumpassword'], TEXT_BOX_SIZE),

);

$format_strings = array();
foreach ($SETTYPES as $t)
    $format_strings[] = new pref_text(CONFIG_LEVEL_MASTER, $LN['settype'][$t], "settype_$t", $LN['settype_msg'][$t], $settype_msg[$t], $prefArray_root["settype_$t"], TEXT_BOX_SIZE);

$pref_list[] = array('name'=>$LN['config_globalsettings'],'value'=> $global_settings);
$pref_list[] = array('name'=>$LN['config_urdd_head'],'value'=> $urdd_cfg);
$pref_list[] = array('name'=>$LN['config_networking'],'value'=> $networking);
$pref_list[] = array('name'=>$LN['config_setinfo'],'value'=> $set_updating);
$pref_list[] = array('name'=>$LN['config_formatstrings'], 'value'=>$format_strings);
$pref_list[] = array('name'=>$LN['config_extprogs'],'value'=> $ext_progs);
$pref_list[] = array('name'=>$LN['config_prog_params'], 'value'=>$prog_params);
if ($URDDONLINE) 
    $pref_list[] = array('name'=>$LN['config_maintenance'],'value'=> $maintenance);
else 
    $pref_list[] = array('name'=>$LN['config_maintenance'],'value'=> $maintenance_offline);


init_smarty( $LN['config_title']);
$smarty->assign('level',                $pref_level);
$smarty->assign('saved',                $saved);
$smarty->assign('imported',             $imported);
$smarty->assign('__message',            $__message);
$smarty->assign('pref_list',            $pref_list);

$smarty->assign('referrer', 		basename(__FILE__, '.php'));
$smarty->display('settings.tpl');


?>
